<?php
/**
 *
 * 版权所有：
 * 作    者：huangwy
 * 日    期：2018-01-15
 * 版    本：
 * 功能说明：QueryList采集插件
 *
 **/
// 本类由系统自动生成，仅供测试用途
namespace Code\Controller;
use Think\Controller;
class CollectController extends Controller {
    public function index(){
        header("Content-type:text/html;charset=UTF-8");
        import('Org.JAE.QueryList');

        //采集OSC的代码分享列表，标题 链接 作者
        $url = "http://www.oschina.net/code/list";
        $reg = array("title"=>array(".code_title a:eq(0)","text"),"url"=>array(".code_title a:eq(0)","href"),"author"=>array("img","title"));
        $rang = ".code_list li";
        //使用curl抓取源码并以GB2312编码格式输出
        $hj = new \QueryList($url,$reg,$rang,'curl','UTF-8');
        $arr = $hj->jsonArr;
        echo "<pre>";
        print_r($arr);
        echo "</pre><hr/>";

        //如果还想采当前页面右边的 TOP40活跃贡献者 图像，得到JSON数据,可以这样写
        $reg = array("portrait"=>array(".hot_top img","src"));
        $hj->setQuery($reg);
        $json = $hj->getJSON();
        echo $json . "<hr/>";

        //采OSC内容页内容
        $url = "http://www.oschina.net/code/snippet_186288_23816";
        $reg = array("title"=>array(".QTitle h1","text"),"con"=>array(".Content","html"));
        $hj = new \QueryList($url,$reg);
        $arr = $hj->jsonArr;
        echo "<pre>";
        print_r($arr);
        echo "</pre><hr/>";

    }

    public function mytest(){
        header("Content-type:text/html;charset=UTF-8");
        import('Org.JAE.QueryList');

        $url = "http://m.pufei.net/manhua/320/";
        $reg = array("title"=>array("a:eq(0)","text"),"url"=>array("a:eq(0)","href"));
        $rang = "#chapterList2 li";
        //使用curl抓取源码并以GB2312编码格式输出
        $hj = new \QueryList($url,$reg,$rang,'UTF-8');
        $arr = $hj->jsonArr;
        echo "<pre>";
        print_r($arr);
        echo "</pre><hr/>";
    }

    public function yyq(){
        header("Content-type:text/html;charset=UTF-8");
        import('Org.JAE.QueryList');

        $url = "http://ac.qq.com/Comic/ComicInfo/id/518333/";
        $reg = array("title"=>array("a","title"),"url"=>array("a","href"),"free"=>array('i','class'));
        $rang = ".works-chapter-list li p .works-chapter-item";
        //使用curl抓取源码并以GB2312编码格式输出
        $hj = new \QueryList($url,$reg,$rang,'UTF-8');
        $arr = $hj->jsonArr;
        echo "<pre>";
        print_r($arr);
        echo "</pre><hr/>";
    }

    public function cpic(){
        header("Content-type:text/html;charset=UTF-8");
        import('Org.JAE.QueryList');

        $url = "http://ac.qq.com/ComicView/index/id/518333/cid/1";
        $reg = array("img"=>array("img","src"),"comic-ft"=>array(".comic-ft","text"));
        $rang = ".comic-contain li";
        //使用curl抓取源码并以GB2312编码格式输出
        $hj = new \QueryList($url,$reg,$rang,'UTF-8');
        $arr = $hj->jsonArr;
        echo "<pre>";
        print_r($arr);
        echo "</pre><hr/>";
    }
}